Who Else Wants To Discover the Astonishingly Simple Secrets to Mastering The Piano in Less Than 30 Days - Guaranteed! Get it now!
I got a great response from my kids with a quick VB script to manipulate a Microsoft Agent character. For those that aren't familiar with MS Agent, it's a series of animated onscreen characters that can be manipulated via a COM interface. You can download the code and characters at the Microsoft Agent download page.
The folllowing few lines will make the Merlin character appear on screen, fly around, knock on the screen to get your attention, and say hello. AgentName = "Merlin" agentPath = "c:\windows\msagent\chars\" & agentName & ". Acs" Set agent = CreateObject("Agent.Control.2") agent.
Connected = TRUE agent.Characters. Load agentName, agentPath Set character = agent.Characters. Character(agentName) character.
Show character. MoveTo 500, 400 character. Play "GetAttention" character.
Speak " how are you? " Wscript. Sleep 15000 character.
Stop character. Play "de" There are a great many other commands you can use. Check http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx for more information.
EDIT 2011-09-02 I recently discovered that Microsoft Agent is not natively installed on Windows 7. However it is offered as a separate download here. I have not tested this so cannot verify whether it operates.
28 This way you can see the paperclip all the time :D – Pedery Dec 19 '09 at 17:47 7 @Bob BASIC is a beginners language. VB is not BASIC. VB is the swiss army knife that MS created to fit the need at the time.
Nowadays, there are much better (much more specialized) tools to take its place. VB isn't a bad language, it just has a lot of excess baggage. If I were to give one completely unbiased reason why not to use it, it would be because MS is slowly dropping support for VB.It's a dying language.
Just wait til Office scripting is done with JavaScript (which is planned in the near future) then the decline of VB will be a sure thing. – Evan Plaice Sep 7 '11 at 23:34 2 @Evan - Thanks for the fair answer, rather than some religious screed. Nicely done.
Hadn't heard about the Office Javascript move. Will investigate. – Bob Mc Sep 8 '11 at 16:48.
Enter this code in your address bar (in your browser) and press enter. Then you can edit all the content of the webpage! Javascript:document.body.
ContentEditable='true'; document. DesignMode='on'; void 0 That is the coolest "one-liner" I know =).
88 "One-liner" is such a misnomer. That's 3 lines, really. Any code can be one line if you want it to be.
– DisgruntledGoat Jul 4 '09 at 20:24 5 This looks really neat, but is there a way to get the page once it is modified? – Sylverdrag Aug 23 '09 at 3:24 1 @Kugel: it works for me in FF. BTW, why'd you put true in quotes?
– Wallacoloo Feb 27 '10 at 21:00 50 I like it so much, I upvoted for you 999999999 times! Img707.imageshack.us/img707/4843/jshack.png – JRL Apr 23 '10 at 18:32 4 This is no longer true in Firefox as javascript: has been disabled. A shame.
– pat Dec 30 '11 at 19:52.
When I first wrote this. 10 PRINT "What is your name? " 20 INPUT A$ 30 PRINT " " A$ 40 GOTO 30 It blew people away!
The computer remembered their name! EDIT: Just to add to this. If you can convince a new programmer this is the coolest thing they can do, they will become the good programmers.
These days, you can do almost anything you want with one line of code to run a library somebody else wrote. I personally get absolutely no satisfaction from doing that and see little benefit in teaching it.
15 would be better with the following: 40 GOTO 30 – spender May 1 '09 at 11:51 8 +1 for displaying username, people always love seeing their own name displayed. @saua, how is that not an infinite print loop? It goes back to line 30, not line 20.
– yx. May 1 '09 at 12:42 13 Should be goto 10 surely so somone else can enter thier name... – Omar Kooheji May 1 '09 at 14:39 16 You forgot 35 PRINT CHR$(7) – Adam Jaskiewicz May 1 '09 at 16:25 6 this is how I learnt programming too. Its the best answer imo.
+1 to accept this one – Click Upvote May 1 '097 at 1:47.
PHP - the Sierpinski gasket a.k. A the Triforce OK, it's 15 lines of code but the result is awesome! That's the kind of stuff that made me freak out when I was a child.
This is from the PHP manual: $x = 200; $y = 200; $gd = imagecreatetruecolor($x, $y); $corners0 = array('x' => 100, 'y' => 10); $corners1 = array('x' => 0, 'y' => 190); $corners2 = array('x' => 200, 'y' => 190); $red = imagecolorallocate($gd, 255, 0, 0); for ($i = 0; $i.
24 For the record, that's a Sierpinski gasket. – chaos May 1 '09 at 12:36 6 That is awesome, but I think it should come in about the middle of the course, because it builds on a number of concepts, like loops and arrays. – Mike Dunlavey May 1 '09 at 12:38 4 @Masi: the general idea is to have three fixed points that are the corners of the triangle, and a "current" point that you keep URL1 make a move, choose one of the corners at random and move the current point half of the way towards that corner.
Color in the current point. Then make another move in the same way, and then again a few thousand more times and the pattern will appear. Then try it with a different number of corners, or change the fraction by which the current point jumps toward the corner, to see how it affects the pattern.
– Daniel Earwicker May 18 '09 at 22:44 17 For the record, that is not a Sierpinski gasket... It is, in fact, the Triforce. En.wikipedia.org/wiki/The_Legend_of_Zelda – jason Jul 19 '09 at 20:54 2 This code seems weird to me because I normally see this done with recursion (also with very few lines of code). In fact, fractals are a good introduction to recursion in computer science classes.
But it looks to me like this code will be quite inefficient, painting & repainting a lot of pixels due to its random approach. – Steve Wortham Sep 15 '09 at 21:59.
Microsoft has Small Basic, an IDE for "kids". Pic = Flickr. GetRandomPicture("beach") Desktop.
SetWallpaper(pic) It is specifically designed to show how cool programming is.
77 This actually sucks, because these library calls seem like magic. You're setting them up to be VB script kiddies. I'm afraid they will never lurk into that "dark magic" area, and stay on the "safe" plumbing area.... Oh look here's how to make an internet browser in one line!
MSIEControl(..blabla whatever...).show() – hasen j May 4 '09 at 0:27 86 I don't think kids are idiots. If you get them excited about the possibilities of programming, they will find out how to do more advanced things on their own. If nothing else, the young testosterone-infected boys would be trying to learn the most arcane, darkmagic things before you even know what happened.
– Tim Lin May 4 '09 at 1:27 27 @hansen j, thats unfair, everybody has to start someplace. – jfar May 7 '09 at 7:34 27 This isn't a CS degree for kids this is a programming toy. Whatever that gateway is to getting kids to see the fun side of programming that's great it doesn't need to be ASM.
– Copas May 19 '09 at 15:14 24 Knowing the kids that I've tried to teach, it'd be about ten seconds before they try pic = Flickr. GetRandomPicture("boobs") – Iain Galloway Dec 20 '10 at 13:00.
I tend to think that people are impressed with stuff that they can relate to or is relevant to their lives. I'd try and base my 10 lines of code around something that they know and understand. Take, for example, Twitter and its API.
Why not use this API to build something that's cool. The following 10 lines of code will return the "public timeline" from Twitter and display it in a console application... using (var xmlr = XmlReader. Create("twitter.com/statuses/public_timeline.rss")) { SyndicationFeed .
Load(xmlr) . GetRss20Formatter() . Feed .
Items .ToList() . ForEach( x => Console. WriteLine(x.Title.
Text)); } My code sample might not be the best for your students. It's written in C# and uses . NET 3.5.So if you're going to teach them PHP, Java, or C++ this won't be useful.
However, my point is that by associating your 10 lines of code with something "cool, interesting, and relevant to the students your sample also becomes cool, interesting, and relevant. Good luck! Yes, I know that I've missed out a few lines of using statements and the Main method, but I'm guessing that the 10 lines didn't need to be literally 10 lines.
14 +1: Showing something that they can relate to would be a huge plus. – Jon Tackabury May 1 '09 at 15:00.
This is a Python telnet server that will ask for the users name and say hello to them. This looks cool because you are communicating with your program from a different computer over the network. From socket import * s=socket(AF_INET, SOCK_STREAM) s.
Bind(("", 3333)) s. Listen(5) while 1: (c, a) = s.accept() c. Send("What is your name?") name = c.
Recv(100) c. Send("close().
I think it's tough to be a computer educator these days. I am. We face an increasingly steep uphill battle.
Our students are incredibly sophisticated users and it takes a lot to impress them. They have so many tools accessible to them that do amazing things. A simple calculator in 10 lines of code?
Why? I've got a TI-83 for that. A script that applies special effects to an image?
That's what Photoshop is for. And Photoshop blows away anything you can do in 10 lines. How about ripping a CD and converting the file to MP3?
Uhh, I already have 50,000 songs I got from BitTorrent. They're already in MP3 format. I play them on my iPod.
Who buys CDs anyway? To introduce savvy users to programming, you're going to have to find something that's: a) applicable to something they find interesting and cool, and b) does something they can't already do. Assume your students already have access to the most expensive software.
Many of them do have the full version of Adobe CS4 (retail price: $2,500; actual price: free) and can easily get any application that would normally break your department's budget. But the vast majority of them have no idea how any of this "computer stuff" actually works. They are an incredibly creative bunch: they like to create things.
They just want to be able to do or make something that their friends can't. They want something to brag about. Here are some things that I've found to resonate with my students: HTML and CSS.
From those they learn how MySpace themes work and can customize them. Mashups. They've all seen them, but don't know how to create them.
Check out Microsoft Popfly and Yahoo! Pipes. There are lots of teachable moments, such as RSS, XML, text filtering, mapping, and visualization.
The completed mashup widgets can be embedded in web pages. Artwork. Look at Context-Free Art.
Recursion and randomization are key to making beautiful pictures. Storytelling. With an easy-to-use 3D programming environment like Alice, it's easy to create high-quality, engaging stories using nothing more than drag-and-drop.
None of these involve any programming in the traditional sense. But they do leverage powerful libraries. I think of them as a different kind of programming.
I've found a big favorite (in GWBASIC) is: 10 input "What is your name ";N$ 20 I = int(rnd * 2) 30 if I = 0 print " You are a " 40 if I = 1 print " You are a " I've found beginning students have a few conceptions that need to be fixed. Computers don't read your mind. Computers only do one thing at a time, even if they do it so fast they seem to do it all at once.
Computers are just stupid machines and only do what they are told. Computers only recognize certain things and these are like building blocks. A key concept is that a variable is something that contains a value and its name is different from that value.
The distinction between the time at which you edit the program and the time at which it runs. Good luck with your class. I'm sure you'll do well.P.S. I'm sure you understand that, along with material and skill, you're also teaching an attitude, and that is just as important.
23 +1 for the insults – Robin Day May 1 '09 at 12:13 5 @dreamlax: You're right, of course, but let's not split hairs. We're talking about introducing computers to kids and giving them the basic mental building blocks. Parallelism can come later.
– Mike Dunlavey May 1 '09 at 12:33 1 @Ben S: Did you by any chance remove the space in front of line 10? I had put that in because it seems the SO formatter seems to un-dent the first line by 1 space. I wonder if there's a better way to make the code line up?
– Mike Dunlavey May 1 '09 at 18:27 2 @foljs: Gosh! Really? :-) dreamlax made the same point.
The thing is, when you're working with people who know nothing about computers, it looks to them as if everything happens at once, so we gotta get over that, without splitting hairs. So a really basic concept is "First it does A, then it does B, and so on. " – Mike Dunlavey May 1 '09 at 0:46.
This C-code is maybe be obfuscated, but I found it very powerful #include float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L|| (h-=o,T= -2),s;4 -(r=O*O)\n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;} And here is the result... In only 3 lines... A kind of fractal .. WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld! Ddllllrrrrrrooooooooooooooooo WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd! OWW!
Dllllllrrrrroooooooooooooo WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd! Orro! O!
Dllllllrrrrrrooooooooooo WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd! WorddddoW! Ddllllllrrrrrrooooooooo WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!
O! DWW! Ddddllllrrrrrrrooooooo WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!
WWWoo WloW! Ddddllrrrrrrrrooooo WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo! Wl r!
DlooWWWoW! Dllrrrrrrroooo WWWoorrrrrrrrrrrrrrrrrlllllddddddd! Wdo l!
Rdo! L! R!
Dlrrrrrrrrooo WWoorrrrrrrrrrrrrrrlllddddddddd! OolWW lW! Ddlrrrrrrrroo WWorrrrrrrrrrrrllld!
Dddd! WWrd! RlW!
Ddllrrrrrrrro Worrrrrrrllllllddd! OooWWWoloWWWWoodr drrWdlllrrrrrrrr Worrrlllllllldddd! WolWrr!
DWWWlrrldr ro! Dlllrrrrrrrr Wrrllllllllddddd! WWolWr oWoo r!
Dllllrrrrrrr Wlllllllldddd! OdrrdW o lWddllllrrrrrrr Wlddddd! WWordlWrd oW!
Ddllllrrrrrrr olddddd! WWordlWrd oW! Ddllllrrrrrrr Wlllllllldddd!
OdrrdW o lWddllllrrrrrrr Wrrllllllllddddd! WWolWr oWoo r! Dllllrrrrrrr Worrrlllllllldddd!
WolWrr! DWWWlrrldr ro! Dlllrrrrrrrr Worrrrrrrllllllddd!
OooWWWoloWWWWoodr droWdlllrrrrrrrr WWorrrrrrrrrrrrllld! Dddd! WWrd!
RlW! Ddllrrrrrrrro WWoorrrrrrrrrrrrrrrlllddddddddd! OolWW lW!
Ddlrrrrrrrroo WWWoorrrrrrrrrrrrrrrrrlllllddddddd! Wdo l! Rdo!
L! R! Dlrrrrrrrrooo WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!
Wl r! DlooWWWoW! Dllrrrrrrroooo WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!
WWWoo WloW! Ddddllrrrrrrrrooooo WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd! O!
WdWW! Ddddllllrrrrrrrooooooo WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd! WorddddoW!
Ddllllllrrrrrrooooooooo WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd! Orro! O!
Dllllllrrrrrrooooooooooo WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd! OWW! Dllllllrrrrroooooooooooooo WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!
Ddllllrrrrrrooooooooooooooooo WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo WWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo WWWWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.
4 Nice! Too bad there isn't any spot on there that actually says "" – Wallacoloo Feb 27 '10 at 21:33.
EDIT: Go to a page with lots of images and try this in the address bar: javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document. Images; DIL=DI. Length; function A(){for(i=0; iLeft=Math.
Sin(R*x1+i*x2+x3)*x4+x5; DIS. Top=Math. Cos(R*y1+i*y2+y3)*y4+y5}R++ }setInterval('A()',5); void(0).
2 ok, but you should give a concrete example you know .. – hasen j May 4 '09 at 0:46 1 @John: Please, give a concrete example. I have only used JS in my server by exporting the JS file. I have never put the code to my address bar.
– Masi May 4 '09 at 18:06 7 Well not a very exciting example, but you could do javascript:alert(" – John Topley May 4 '09 at 21:02.
You could make an application that picks a random number. And you have to guess it. If you are wrong it says: higher or lower.
And if you guessed it, a nice message. It's cool to play for the students. Simple Python version without proper error checking: import random while input('Want to play higher/lower?').lower().
Startswith('y'): n = random. Randint(1, 100) g = int(input('Guess: ')) while g! = n: print(' %ser!
' % (g > n and 'low' or 'high')) g = int(input('Guess: ')) print(' Correct! Congratulations!') Erik suggests that the computer should guess the number. This can be done within 10 lines of code as well (though now the lack of proper error checking is even more serious: valid numbers outside the range cause an infinite loop): while input('Want to let the pc play higher/lower?
').lower(). Startswith('y'): n = int(input('Give a number between 1 and 100: ')) lo, hi, guess, tries = 1, 100, 50, 1 while guess! = n: tries += 1 lo, hi = (guess + 1, hi) if guess.
4 binary search! :) – Andrioid May 19 '09 at 9:00 4 More interesting would be to have the user pick the random number, then have the computer guess it. – Erik Forbes Jun 15 '09 at 22:17 5 binary solo!
:) – MGOwen Jul 22 '09 at 6:41 14 Now make these two programs play each other over a socket. – Josh Lee Dec 4 '09 at 9:14 3 It'd be better if the computer wasn't given the number directly. You should tell the user to "pick a number between 1 and 100".
Then output "I guess 50", and ask for input ("higher", "lower", or "correct") and refine your guess. – Wallacoloo Feb 27 '10 at 21:10.
Back in computer class in high school, myself and a couple of friends taught the class how to program with Delphi. The class was mostly focused on programming with Pascal, so Delphi was a good next step. We demonstrated the event driven nature of Delphi and its RAD capabilities.At the end of the lesson we showed the class a sample application and asked them to reproduce it.
The application asked "Are you drunk? " with two buttons Yes and No....I think you know what is coming next...the No button changed locations on mouse over and was almost impossible to click. The students and teacher got a good kick out of it.
The program only required a few lines of user-written code with a simple equation to calculate where to move the button. I don't think any of the other students figured it out, but a few were close.
2 ++ Good entertaining trick. – Mike Dunlavey May 1 '09 at 18:36 7 Not only entertaining, but a coworker of mine once did that in some software, only it was the "OK" button on a message box. It was an internally used app so it wasn't frowned upon.It only did this once in a blue moon.
Of course they'd call him and he would say he needed to see it happen if he was going to believe it. So he'd wander over and of course it wouldn't happen when he was there... – Jason D Nov 27 '09 at 5:02 2 That would be an interesting time to teach people to navigate via tab and space. – dah Dec 30 '11 at 15:55.
In this day and age, JavaScript is an excellent way to show how you can program using some really basic tools e.g. Notepad. JQuery effects are great starting point for anyone wanting to wow their friends! In this one, just click the white space of the page.
1 I would agree. You can open notepad and start coding away with java script and then open a browser and I'm sure your students will be impressed. These are tools everyone has and they can look up a lot of different effects and stuff that can be done like Jon's example.
– Jeff Reddy Aug 23 '11 at 17:38 1 I don't think it's a good idea to teach someone the base of a fairly simple language using a library. You can easily do this without using jQuery, and for a beginner, you should. Libraries are not a replacement to the actual language.
– Amaan Dec 31 '11 at 11:35.
When I first figured out the bash forkbomb, I thought it was really sweet. So simple, yet neat in what it can do: :(){ :|:& }.
7 Here's a pretty good explanation: cyberciti. Biz/faq/understanding-bash-fork-bomb – Matt Jun 21 '09 at 23:52 11 for new to linux guys:don't run, else you will loose all your work. – Behrooz Jul 7 '10 at 16:29.
This is cheating, and not even remotely simple, but I once wrote a shoot'em up in 20 lines of C++, using the Allegro graphics library. No real criteria for what a line was, but it was a bit ago, and it was made purely for fun. It even had crude sound effects.
Here's what it looked like: And here's the code (should compile): bool inside(int x, int y, int x2, int y2) { return (x>x2&&xy2&&y228?228:px))) &&! KeyKEY_ESC) { rectfill(buffer,0,0,244,240,makecol32(0,0,0)); for(int i=0;i8?(monstarsi==-100?0:0.02):-100, points = monstarsi>240? Points-1:points, monstarsi=monstarsi>240?
-100:monstarsi, points = inside(shotx,shoty,i*32,monstarsi)? Points+1:points, (monstarsi = inside(shotx,shoty,i*32,monstarsi)? Shoty=-1?
-100:-100:monstarsi), maxp = maxp>points? Maxp:points, i++) for (int j=1; j0) rectfill(buffer,shotx,shoty-=0.1,shotx+2,shoty+2,makecol32(0,255,255)); // rysowanie strzalu for (int i=1; i.
On an unrelated note, COOL! HA! Loved it!
– Santiago Lezica Dec 31 '11 at 9:38.
One thing you might consider is something like Robocode, in which a lot of coding is abstracted away and you basically just tell a robot what to do. A simple 10-line function can make the robot do a great deal, and has a very visual and easy-to-follow result. Perhaps Robocode itself isn't suited to the task, but this kind of thing is a good way to relate written code to visual actions on the computer, plus it's fun to watch for when you need to give examples.
Public class MyFirstJuniorRobot extends JuniorRobot { public void run() { setColors(green, black, blue); // Seesaw forever while (true) { ahead(100); // Move ahead 100 turnGunRight(360); // Spin gun around back(100); // Move back 100 turnGunRight(360); // Spin gun around } } public void onScannedRobot() { turnGunTo(scannedAngle); fire(1); } public void ontByBullet() { turnAheadLeft(100, 90 - hitByBulletBearing); } }.
6 Don't know about robocode, but I got into coding after using Logo. Being able to draw a house using forward, backward, left, right, etc. It gets you into the mindset of simple instructions performing huge tasks. – Robin Day May 1 '09 at 12:15 1 Yeah I learned Logo in computer lab in elementary school.
I was one of the kids who, beyond thinking it was cool, wanted to know more. – T Pops May 1 '09 at 19:34 1 +1 For RoboCode! I love robocode, and we used to do competitions between ourselves to see who would come up with the best algorithms – Andreas Grech May 2 '09 at 4:22.
So one day, I decided that I'd had enough. I would learn piano. Seeing people like Elton John command such mastery of the keyboard assured me that this was what I wanted to do.
Actually learning piano was a huge letdown. Even after completing eight grades of piano lessons, I was still not impressed with how my mental image of playing piano was so different from my original vision of enjoying the activity. However, what I thoroughly enjoyed was my mere three grades of rudiments of music theory.
I learned about the construction of music. I was finally able to step from the world of performing written music to writing my own music. Subsequently, I was able to start playing what I wanted to play.
Don't try to dazzle new programmers, especially young programmers. The whole notion of "less than ten lines of simple code" seems to elicit a mood of "Show me something clever". You can show a new programmer something clever.
You can then teach that same programmer how to replicate this "performance". But this is not what gets them hooked on programming. Teach them the rudiments, and let them synthesize their own clever ten lines of code.
I would show a new programmer the following Python code: input = open("input. Txt", "r") output = open("output. Txt", "w") for line in input: edited_line = line edited_line = edited_line.
Replace("EDTA", "ethylenediaminetetraacetic acid") edited_line = edited_line. Replace("ATP", "adenosine triphosphate") output. Write(edited_line) I realize that I don't need to assign line to edited_line.
However, that's just to keep things clear, and to show that I'm not editing the original document. In less than ten lines, I've verbosified a document. Of course, also be sure to show the new programmer all the string methods that are available.
More importantly, I've showed three fundamentally interesting things I can do: variable assignment, a loop, file IO, and use of the standard library. I think you'll agree that this code doesn't dazzle. In fact, it's a little boring.No - actually, it's very boring.
But show that code to a new programmer and see if that programmer can't repurpose every part of that script to something much more interesting within the week, if not the day. Sure, it'll be distasteful to you (maybe using this script to make a simple HTML parser), but everything else just takes time and experience.
Like most of the other commenters, I started out writing code to solve math problems (or to create graphics for really terrible games that I would design -- things like Indiana Jones versus Zombies). What really started me (on both math and programming) was going from text based, choose your own adventure style games...to more graphics-based games. I started out coloring graph paper and plotting pixels, until I got into geometry...and discovered how to use equations to plot curves and lines, boxes, etc.My point is, I could have really gotten into something like processing ( processing.org/ ) where a typical program looks something like this: void setup() { size(200, 200); noStroke(); rectMode(CENTER); } void draw() { background(51); fill(255, 204); rect(mouseX, height/2, mouseY/2+10, mouseY/2+10); fill(255, 204); int inverseX = width-mouseX; int inverseY = height-mouseY; rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10); } To me, this is the "Logo" of the future.
There are easy "hello world" examples that can quickly get someone drawing and changing code and seeing how things break and what weird "accidents" can be created...all the way to more advanced interaction and fractal creation...
You could use a script written with AutoIt, which blurs the line between using a traditional application and programming. E.g. A script which opens notepad and makes their own computer insult them in it and via a message box, and then leaves no trace of its actions: Run("notepad.
Exe") WinWaitActive("Untitled - Notepad") Send("You smell of human. ") Sleep(10000) MsgBox(0, "Humans smell bad", "Yuck! ") WinClose("Untitled - Notepad") WinWaitActive("Notepad", "Do you want to save") Send("!
N").
I remember when I first started coding loops always impressed me. You write 5 - 10 lines of code (or less) and hundreds (or however many you specify) lines print out. (I learned first in PHP and Java).
For( int I = 0; I.
I think a good place for a student to get started could be Greasemonkey. There are thousands of example scripts on userscripts.org, very good reading material, some of which are very small. Greasemonkey scripts affect web-pages, which the students will already be familiar with using, if not manipulating.
Greasemonkey itself offers a very easy way to edit and enable/disable scripts while testing. As an example, here is the "Google Two Columns" script: result2 = ''; gEntry = document. Evaluate("//li@class='g' | //div@class='g' | //li@class='g w0' | //li@class='g s w0'",document,null,XPathResult.
UNORDERED_NODE_SNAPSHOT_TYPE,null); for (var I = 0; I '+gEntry. SnapshotItem(i). InnerHTML+''; } if(i%2 == 1) { result2 += ''+gEntry.
SnapshotItem(i). InnerHTML+''; } } sDiv. InnerHTML = result2+''; if (document.
GetElementById('mbEnd')! == null) { document. GetElementById('mbEnd').style.
Display = 'none'; }.
This is a very rudimentary text-based c# program that simulates the spinning action of a slot machine. It doesn't include different odds of winning or cash payouts, but that could be a nice exercise for the students. Sorry that it is more than 10 lines.
String symbols = new { "#", "? ", "~" }; // The symbols on the reel Random rand = new Random(); do { string a="",b="",c=""; for( int I = 0; I Next( 0, symbols. Length ); if( I Length ); c = symbolsrand.
Next( 0, symbols. Length ); Console.Clear(); Console. WriteLine( "Spin: " + a + be + c ); } if( a == be && be == c ) Console.
WriteLine( "You win. Press enter to play again or type \"exit\" to exit" ); else Console. WriteLine( "You lose.
Press enter to play again or type \"exit\" to exit" ); } while( Console.ReadLine()! = "exit" ).
With Tcl you have a simple text editor with a save button in about 12 lines of code (but no open, that would take another 8 lines). It works across all standard platforms: pack frame . Toolbar -side top -fill x pack button .
Save -text save -command save -in . Toolbar -side left pack scrollbar . Vsb -orient vertical -command list .
Text yview -side right -fill y pack text . Text -wrap word -yscrollcommand list . Vsb set -side left -fill both -expand true proc save {} { set filename tk_getSaveFile if {$filename ne ""} { set f open $filename w puts $f .
Text get 1.0 end-1c close $f } } I realize the goal was 10 lines, so if you want the to stick to 10 lines or less, a simple text editor without load or save is only two lines. That's not too shabby. Pack scrollbar .
Vsb -orient vertical -command list . Text yview -side left -fill y pack text . Text -wrap word -yscrollcommand list .
Vsb set -side left -fill both -expand true Execute either of the above blocks of code with "wish filename" on the platform of your choice. Wish comes with most *nix's and the mac but you'll have to install it manually for windows. To go a step further, that two line script can also be written in python, though it takes eight lines, still under the 10 line goal: from Tkinter import * root=Tk() text = Text(wrap="word") sb = Scrollbar(orient="vertical", command=text.
Yview) text. Configure(yscrollcommand=sb. Set) sb.
Pack(side="right", fill="y") text. Pack(side="left", fill="both", expand=True) root.mainloop().
It would show them how to manipulate something that they use every day (the Internet) without requiring any development tools.
If you can afford the hardware, using an Arduino board + processing will produce some pretty cool things, though it may be a little advanced for people that may not be interested at all in programming.
I wrote about this recently in an article "The Shortest, most useful program I have ever written. " Summary: I wrote a 3 line VB6 app back in 1996 that I still use every single day. Once the exe is dropped in the "Send-to" folder.It lets you right click on a file in explorer and send the full path of that file to the clipboard.
Public Sub Main() Clipboard. SetText Command$ End Sub.
It's interesting that you mention the Mandelbrot set, as creating fractals with GW-BASIC is what sparked my love of programming back in high school (around 1993). Before we started learning about fractals, we wrote boring standard deviation applications and I still planned to go into journalism. But once I saw that long, difficult-to-write BASIC program generate "fractal terrain," I was hooked and I never looked back.It changed the way I thought about math, science, computers, and the way I learn.
I hope you find the program that has the same affect on your students.
WxPython First Steps import wx app = wx.App() wx. Frame(None, -1, 'simple. Py').Show() app.MainLoop().
This would show them how interactive programs work. It would also show them that they, as programmer, are in complete control of what the computer (program) does. Hopefully it would lead them to make suggestions for other things they could change and then onto other things they might want to do.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.